[#import "/framework/JGP.htm"  as JGP]
<!--
项目   parent
作者   LOUFEI [Gavin]
时间   2018/5/7
-->
[@JGP.head "Title"/]
[@JGP.body]


<jgp-div slot="1-1" _row="['40','*']" _runit="px">
    <div slot="1-1">
        <jgp-btn _fn="save">保存</jgp-btn>
    </div>
    <jgp-panel slot="2-1" _padding="10px" _border="right">
        <jgp-tree _id="roleTree" _root="角色树" _check="true" _icon="false"
                  _onclick="setFormData"
                  _onload="initTree"
                  _url="/security/admin/adminApiController/treeRole"></jgp-tree>
    </jgp-panel>
</jgp-div>


[/@JGP.body]

[@JGP.foot]
    <script>
        var selected;
        function initTree(){
            if(!selected){
                JGP.$get('/security/admin/adminApiController/queryUserRoles/${userId!''}', {},
                        function (result) {
                            selected = result.data.roleIds;
                            JGP.tree('roleTree').setSelected(selected);
                        })
            }
        }

        function save() {
            var selected = JGP.tree('roleTree').getSelected();
            if (selected === -1) {
                JGP.$warn('没有选择角色');
                return;
            }
            var userId = '${userId!''}';
            var roleIds = [];
            for (var i = 0; i < selected.length; i++) {
                roleIds.push(selected[i].id);
            }
            JGP.$get('/security/admin/adminApiController/changeUserRoles', {
                        roleIds: roleIds + '',
                        userId: userId
                    },
                    function (result) {
                        JGP.$alert('角色修改成功');
                    }, function () {
                        JGP.$error('错误');
                    })

        }

    </script>
[/@JGP.foot]